
	
$('document').ready(function() {
	if ($('.auction_row').length > 0)
		setInterval(function() {
			getAuctionsPerInterval(auctionList);
		}, 1000);
});

function getAllAuctionDetail(){
	$.ajax({
		type : "POST",
		url : "/admin/pages/ajax/getAllAuction.php", 
		async : true,
		data: {refresh: true},
		success : function(data) {
			
			data = $.parseJSON(data);
			$('table tbody tr').remove();
			var htmlStr= "";
			$
					.each(data,
							function(key, value) {
									
									htmlStr = htmlStr + "<tr ref='row-" + value.auctionID + "'> "+
										"<td><input  class='auction_check' type='checkbox' refid='"+value.auctionID+"'/></td>"+
										"<td><span class='auctionID'>" + value.auctionID + "</span></td>"+
										"<td><span class='name'>" + value.name + "</span></td>"+
										"<td><span class='pro_name'>" + value.name + "</span></td>"+
										"<td><span class='status'>" + value.status + "</span></td>"+
										"<td><span class='start_time'>" + value.start_time + "</span></td>"+
										"<td><span class='end_time'>" + value.end_time + "</span></td>"+
										"<td><span class='price'>" + value.price + "</span></td>"+
										"<td><span class='auction_price'>" + value.auction_price + "</span></td>"+
										"<td><span class='quantity'>" + value.quantity + "</span></td>"+
										"<td><span class='current_user_bid'>" + value.current_user_bid + "</span></td>"+
										"<td><span class='price_per_bid'>" + value.price_per_bid + "</span></td>"+
										"<td> <a title='Edit'><img src='/admin/resources/images/icons/pencil.png' alt='Edit' /></a>"+
											 "<a href='#' title='Delete' onclick ='deleteOneAuction("+value.auctionID+")'><img src='/admin/resources/images/icons/cross.png' alt='Delete' /></a>" + 
										
										"</td> </tr>";
									

								});
			$('table tbody').html(htmlStr);
		
		}
	});	
}
function getAuctionsPerInterval(auctionList) {

	var auction_list = auctionList.join(",");
	
	$.ajax({
		type : "POST",
		url : "/admin/pages/ajax/getAuctionsPerInterval.php", 
		async : true,
		data: {data: auction_list},
		success : 	function(data){ 
			data = $.parseJSON(data);
			$
					.each(data,
							function(key, value) {
								var refer = 'table tbody tr[ref="row-' + value.auctionID
								+ '"]';
								
								var auction = $(refer);

								auction.find('.end_time').html(
										value.end_time);
								auction.find('.auction_price ').html(
										value.auction_price);
								auction.find('.current_user_bid').html(
											value.current_user_bid);

							})
		}

	}
)

			
}

function deleteAuctions(auctionList) {

	var auction_list = auctionList.join(",");
	
	$.ajax({
		type : "POST",
		url : "/admin/pages/ajax/deleteAuctions.php", 
		async : true,
		data: {data: auction_list},
		success : function(data) {
			
			data = $.parseJSON(data);
			$('table tbody tr').remove();
			var htmlStr= "";
			$
					.each(data,
							function(key, value) {
								if (value.error ==false){
									
						$('.message').html(
								'<div class="notification success png_bg">'+
									'<a href="#" class="close"><img src="/admin/resources/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>'
										+'<div> Delete Rows Successful </div>'+
								'</div>');
								}
								else {
									$('.message').html(
											'<div class="notification error png_bg">'+
												'<a href="#" class="close"><img src="/admin/resources/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>'
													+'<div> Can Not Delete These Rows </div>'+
											'</div>');
																		
								}
								
									htmlStr = htmlStr + "<tr ref='row-" + value.auctionID + "'> "+
									"<td><input  class='auction_check' type='checkbox' refid='"+value.auctionID+"'/></td>" +
										"<td><span class='auctionID'>" + value.auctionID + "</span></td>"+
										"<td><span class='name'>" + value.name + "</span></td>"+
										"<td><span class='pro_name'>" + value.name + "</span></td>"+
										"<td><span class='status'>" + value.status + "</span></td>"+
										"<td><span class='start_time'>" + value.start_time + "</span></td>"+
										"<td><span class='end_time'>" + value.end_time + "</span></td>"+
										"<td><span class='price'>" + value.price + "</span></td>"+
										"<td><span class='auction_price'>" + value.auction_price + "</span></td>"+
										"<td><span class='quantity'>" + value.quantity + "</span></td>"+
										"<td><span class='current_user_bid'>" + value.current_user_bid + "</span></td>"+
										"<td><span class='price_per_bid'>" + value.price_per_bid+ "</span></td>"+
										"<td> <a title='Edit'><img src='/admin/resources/images/icons/pencil.png' alt='Edit' /></a>"+
											 "<a href='#' title='Delete' onclick ='deleteOneAuction("+value.auctionID+")'><img src='/admin/resources/images/icons/cross.png' alt='Delete' /></a>" + 
										
										"</td> </tr>";
									
								}

								);
			$('table tbody').html(htmlStr);
		
	}

		,error: function(){
			alert('Deleted auctions errors');
		}});
	}

/*									 
auction.find('.name').html(
		value.name);
auction.find('.pro_name').html(
		value.pro_name);
auction.find('.status').html(
			value.status);
auction.find('.start_time').html(
		value.start_time);
auction.find('.end_time').html(
		value.end_time);
auction.find('.price ').html(
		value.price);
auction.find('.auction_price ').html(
		value.auction_price);
auction.find('.quantity').html(
		value.quantity);
auction.find('.current_user_bid').html(
			value.current_user_bid);
auction.find('.price_per_bid').html(
		value.price_per_bid);
}
else {

}

*/
function showAuctionDetails(){
	
}